package com.bsj.power.system.web;

import cn.dev33.satoken.annotation.SaIgnore;
import com.alibaba.fastjson2.JSONObject;
import com.bsj.power.common.config.exception.ApiException;
import com.bsj.power.common.config.global.JsonResult;
import com.bsj.power.common.config.global.JsonResultEnum;
import com.bsj.power.common.constant.NumericalConstants;
import com.bsj.power.common.def.entity.job.Job;
import com.bsj.power.common.def.vo.homePage.DataStatisticsVO;
import com.bsj.power.common.def.vo.homePage.JobLinkCountVO;
import com.bsj.power.common.def.vo.pls.AlarmReportVO;
import com.bsj.power.common.def.vo.pls.DeviceTypeVO;
import com.bsj.power.common.mapper.JobMapper;
import com.bsj.power.system.service.HomePageService;
import com.bsj.power.system.service.OpenApiService;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.hikvision.artemis.sdk.constant.Constants;
import com.hikvision.artemis.sdk.constant.ContentType;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.*;

/**
 * @author LiJiaXin
 * @version 1.0.0
 * @description 首页单屏
 * @time 2024/6/7 10:30
 */
@Slf4j
@RestController
@RequestMapping("/system/homePage")
public class HomePageController {

    @Autowired
    private HomePageService homePageService;

    @Autowired
    private OpenApiService openApiService;

    @Resource
    private JobMapper jobMapper;

    /**
     * 单屏数据
     *
     * @return com.bsj.power.common.config.global.JsonResult<com.bsj.power.common.def.vo.homePage.DataStatisticsVO>
     * @author ljx
     * @time 2024/6/7 11:10
     */
    @SaIgnore
    @GetMapping("/dataStatistics")
    public JsonResult<DataStatisticsVO> dataStatistics() {
        return JsonResult.success(homePageService.dataStatistics());
    }

    /**
     * 报警信息
     *
     * @param alarmType
     * @return com.bsj.power.common.config.global.JsonResult<java.util.List < com.bsj.power.common.def.vo.pls.AlarmReportVO>>
     * @author ljx
     * @time 2024/6/11 13:59
     */
    @GetMapping("/alarmInfo")
    public JsonResult<List<AlarmReportVO>> alarmInfo(Integer alarmType) {
        return JsonResult.success(homePageService.alarmInfo(alarmType));
    }

    /**
     * 获取统计数据
     *
     * @return com.bsj.power.common.config.global.JsonResult<java.util.List < com.bsj.power.common.def.vo.pls.DeviceTypeVO>>
     * @author ljx
     * @time 2024/6/11 17:18
     */
    @GetMapping("/getStatisticsData")
    public JsonResult<List<DeviceTypeVO>> getStatisticsData() {
        return JsonResult.success(homePageService.getStatisticsData());
    }

    /**
     * 获取天气信息
     *
     * @param
     * @return com.bsj.power.common.config.global.JsonResult<com.alibaba.fastjson2.JSONObject>
     * @author ljx
     * @time 2024/6/17 15:02
     */
    @GetMapping("/getWeatherInfo")
    public JsonResult<JSONObject> getWeatherInfo() {
        return JsonResult.success(homePageService.getWeatherInfo());
    }

    /**
     * 设置时间为安全运行天数起始时间
     *
     * @param date
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/7/8 16:23
     */
    @GetMapping("/resetTime")
    public JsonResult resetTime(String date) {
        return JsonResult.success(homePageService.resetTime(date));
    }

    /**
     * 获取安全运行天数起始时间
     *
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/9/13 20:30
     */
    @GetMapping("/getSafetyDayTime")
    public JsonResult<String> getSafetyDayTime() {
        return JsonResult.success(homePageService.getSafetyDayTime());
    }

    /**
     * 测试人员信息同步
     *
     * @return
     */
    @SaIgnore
    @GetMapping("/syncPersonnelInfo")
    public JsonResult syncPersonnelInfo() {
        openApiService.syncHrmUserInfo();
        return JsonResult.success();
    }


//    /**
//     * 清除p开头的工单
//     *
//     * @return
//     */
//    @SaIgnore
//    @GetMapping("/cleanJobNum")
//    public JsonResult cleanJobNum() {
//        openApiService.cleanJobNum();
//        return JsonResult.success();
//    }

    /**
     * 同步作业工单数据
     *
     * @return
     */
    @SaIgnore
    @GetMapping("/syncWorkInfo")
    public JsonResult syncWorkInfo() {
        openApiService.syncSysWorkList();
        return JsonResult.success();
    }

    /**
     * 同步修改作业工单数据
     *
     * @return
     */
    @SaIgnore
    @GetMapping("/syncUpdateWorkInfo")
    public JsonResult syncUpdateWorkInfo() {
        openApiService.syncUpdateSysWorkList();
        return JsonResult.success();
    }

    /**
     * 重置同步获取负责人联系方式
     *
     * @return
     */
    @SaIgnore
    @GetMapping("/setPersonnelPhone")
    public JsonResult setPersonnelPhone() {
        openApiService.setPersonnelPhone();
        return JsonResult.success();
    }

    /**
     * 清除作业人员脏数据
     *
     * @return
     */
    @SaIgnore
    @GetMapping("/clearDirtyData")
    public JsonResult clearDirtyData() {
        openApiService.clearDirtyData();
        return JsonResult.success();
    }

    /**
     * 改绑场景
     *
     * @return
     */
    @SaIgnore
    @GetMapping("/changeBindScene")
    public JsonResult changeBindScene(String oldScene, String newScene) {
        openApiService.changeBindScene(oldScene, newScene);
        return JsonResult.success();
    }

    /**
     * 同步设备信息
     *
     * @return
     */
    @SaIgnore
    @GetMapping("/syncDevice")
    public JsonResult syncDevice() {
        openApiService.syncDeviceInfo();
        return JsonResult.success();
    }

    /**
     * 获取工单关联的人员数据统计
     *
     * @param jobId
     * @return
     */
    @SaIgnore
    @GetMapping(value = "/queryJobLinkCount")
    public JsonResult<JobLinkCountVO> queryJobLinkCount(Long jobId) {
        if (jobId == null) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        return homePageService.queryJobLinkCount(jobId);
    }



    /**
     * 获取该作业工单下面作业人员的报警信息
     *
     * @param jobId
     * @return
     */
    @GetMapping(value = "/queryJobAlarmList")
    public JsonResult<List<AlarmReportVO>> queryJobAlarmList(Long jobId) {
        if (jobId == null) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        return homePageService.queryJobAlarmList(jobId);
    }

}
